Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Sep 5, 2025

Link issues

fixes #6716

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Introduce IModbusFactory support by registering the service, adding a dedicated documentation page, updating navigation menus, and refining sample components.

New Features:

  • Register IModbusFactory via services.AddModbusFactory
  • Add ModbusFactories demo page to document IModbusFactory usage

Enhancements:

  • Add Modbus menu entry with a badge in the navigation
  • Remove redundant AddTcpSocketFactory from shared extensions
  • Rename and adjust socket factory demo registration and badge count

Documentation:

  • Provide detailed IModbusFactory usage instructions in ModbusFactories.razor and associated code-behind
  • Update sample code for socket factory registration and usage
  • Add localization entries for Modbus menu and factory labels

Copilot AI review requested due to automatic review settings September 5, 2025 07:51
@bb-auto bb-auto bot added the documentation Improvements or additions to documentation label Sep 5, 2025
@bb-auto bb-auto bot added this to the 9.10.0 milestone Sep 5, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 5, 2025

Reviewer's Guide

This PR integrates IModbusFactory into the project by updating menus, DI registration, sample code, and adding a new ModbusFactories documentation component with detailed usage instructions.

File-Level Changes

Change Details Files
Integrate Modbus menu entries and update badge counts
  • Added new DemoMenuItem for ModbusComponents and defined AddModbus method
  • Incremented badge count for socket menu to reflect new items
  • Removed duplicate TcpSocketFactory entry under Services menu
MenusLocalizerExtensions.cs
Register ModbusFactory and adjust TcpSocketFactory in DI
  • Added services.AddModbusFactory() in server service collection
  • Added services.AddTcpSocketFactory() in ServiceCollectionExtensions
  • Removed redundant services.AddTcpSocketFactory() from shared extensions
ServiceCollectionExtensions.cs
ServiceCollectionSharedExtensions.cs
Update socket factory sample code and namespace
  • Replaced AddBootstrapBlazorTcpSocketFactory() with AddTcpSocketFactory() in sample
  • Adjusted SocketFactories component namespace to Components.Samples.Sockets
SocketFactories.razor
SocketFactories.razor.cs
Add new ModbusFactories documentation component
  • Created ModbusFactories.razor with usage steps, code samples, and protocol handling guide
  • Added corresponding code-behind ModbusFactories.razor.cs
ModbusFactories.razor
ModbusFactories.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6716 Add documentation for IModbusFactory, including sample code usage.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 3ecc842 into main Sep 5, 2025
2 of 3 checks passed
@ArgoZhang ArgoZhang deleted the doc-modbus branch September 5, 2025 07:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds IModbusFactory documentation to the BootstrapBlazor.Server project. The changes include new documentation pages, localization entries, menu navigation updates, and package dependencies for Modbus serial communication services.

  • Creates comprehensive documentation for IModbusFactory service usage
  • Adds localization support for both Chinese and English
  • Reorganizes navigation structure to separate Socket and Modbus components

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/BootstrapBlazor.Server/Locales/zh-CN.json Adds Chinese localization entries for Modbus components and updates Socket service descriptions
src/BootstrapBlazor.Server/Locales/en-US.json Adds English localization entries for Modbus components and updates Socket service descriptions
src/BootstrapBlazor.Server/Extensions/ServiceCollectionSharedExtensions.cs Removes ITcpSocketFactory service registration from shared extensions
src/BootstrapBlazor.Server/Extensions/ServiceCollectionExtensions.cs Adds ITcpSocketFactory and IModbusFactory service registrations
src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs Reorganizes menu structure to separate Socket and Modbus components with updated navigation
src/BootstrapBlazor.Server/Components/Samples/Sockets/SocketFactories.razor.cs Updates namespace to match new directory structure
src/BootstrapBlazor.Server/Components/Samples/Sockets/SocketFactories.razor Updates service registration method name
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor.cs Creates new component class for Modbus factory documentation
src/BootstrapBlazor.Server/Components/Samples/Modbus/ModbusFactories.razor Creates comprehensive documentation page for IModbusFactory usage
src/BootstrapBlazor.Server/BootstrapBlazor.Server.csproj Adds Longbow.Modbus package dependency
exclusion.dic Adds spelling exclusions for Modbus-related terms

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +28 to +32
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SendAsync</code> 发送协议数据</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>Close</code> 关闭连接</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SetDataHandler</code> 方法设置数据处理器</li>
<li>通过 <code>ITcpSocketClient</code> 实例属性 <code>ReceivedCallBack</code> 方法设置接收数据处理器(注意:此回调未做任何数据处理为原始数据)</li>
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation incorrectly references ITcpSocketClient methods when describing IModbusClient usage. These should be updated to reference the appropriate Modbus client interface methods instead of TCP socket methods.

Suggested change
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SendAsync</code> 发送协议数据</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>Close</code> 关闭连接</li>
<li>通过 <code>ITcpSocketClient</code> 实例方法 <code>SetDataHandler</code> 方法设置数据处理器</li>
<li>通过 <code>ITcpSocketClient</code> 实例属性 <code>ReceivedCallBack</code> 方法设置接收数据处理器(注意:此回调未做任何数据处理为原始数据)</li>
<li>通过 <code>IModbusClient</code> 实例方法 <code>ConnectAsync</code> 连接远端节点(如有需要)</li>
<li>通过 <code>IModbusClient</code> 实例方法 <code>ReadCoilsAsync</code> 或 <code>ReadRegistersAsync</code> 读取数据</li>
<li>通过 <code>IModbusClient</code> 实例方法 <code>WriteSingleCoilAsync</code> 或 <code>WriteSingleRegisterAsync</code> 写入数据</li>
<li>通过 <code>IModbusClient</code> 实例方法 <code>Close</code> 关闭连接</li>
<li>如需处理接收数据,可通过相关事件或回调方法进行设置(具体请参考 <code>IModbusClient</code> 的文档)</li>

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +72
private ITcpSocketFactory? TcpSocketFactory { get; set; }

private async Task CreateClient()
{
// 创建 ITcpSocketClient 实例
var client = TcpSocketFactory.GetOrCreate("localhost", 0);

// 设置数据适配器 使用 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据
var adapter = new DataPackageAdapter
{
DataPackageHandler = new FixLengthDataPackageHandler(4)
};

// 如果 client 不销毁切记使用 RemoveDataPackageAdapter 移除回调委托防止内存泄露
client.AddDataPackageAdapter(adapter, buffer =>
{
// buffer 即是接收到的数据
return ValueTask.CompletedTask;
});

// 连接远端节点 连接成功后自动开始接收数据
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code example incorrectly shows using ITcpSocketFactory and ITcpSocketClient in Modbus documentation. This should demonstrate IModbusFactory and IModbusClient usage instead.

Suggested change
private ITcpSocketFactory? TcpSocketFactory { get; set; }
private async Task CreateClient()
{
// 创建 ITcpSocketClient 实例
var client = TcpSocketFactory.GetOrCreate("localhost", 0);
// 设置数据适配器 使用 FixLengthDataPackageHandler 数据处理器处理数据定长 4 的数据
var adapter = new DataPackageAdapter
{
DataPackageHandler = new FixLengthDataPackageHandler(4)
};
// 如果 client 不销毁切记使用 RemoveDataPackageAdapter 移除回调委托防止内存泄露
client.AddDataPackageAdapter(adapter, buffer =>
{
// buffer 即是接收到的数据
return ValueTask.CompletedTask;
});
// 连接远端节点 连接成功后自动开始接收数据
private IModbusFactory? ModbusFactory { get; set; }
private async Task CreateModbusClient()
{
// 创建 IModbusClient 实例
var client = ModbusFactory.GetOrCreateTcpMaster("modbus", options =>
{
options.LocalEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
});
// 设置数据包处理器(如有需要,可自定义处理器)
var handler = new FixLengthDataPackageHandler(4);
client.SetDataHandler(handler, buffer =>
{
// buffer 即是接收到的数据
return ValueTask.CompletedTask;
});
// 连接远端 Modbus 设备

Copilot uses AI. Check for mistakes.
}</Pre>

<p class="code-label">针对第三方程序集的数据类型解决方案如下</p>
<p>使用 <code></code></p>
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty code tags with no content. This appears to be incomplete documentation that should either be removed or completed with the intended content.

Suggested change
<p>使用 <code></code></p>
<p>使用</p>

Copilot uses AI. Check for mistakes.
<PackageReference Include="BootstrapBlazor.VideoPlayer" Version="9.0.3" />
<PackageReference Include="BootstrapBlazor.WinBox" Version="9.0.7" />
<PackageReference Include="Longbow.Logging" Version="9.0.1" />
<PackageReference Include="Longbow.Modbus" Version="9.0.0-beta01" />
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a beta version (9.0.0-beta01) in production code may introduce instability. Consider using a stable release version if available.

Suggested change
<PackageReference Include="Longbow.Modbus" Version="9.0.0-beta01" />
<PackageReference Include="Longbow.Modbus" Version="9.0.0" />

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ec0c0b) to head (0042098).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6717   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31713     31713           
  Branches      4462      4462           
=========================================
  Hits         31713     31713           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The badge count for the Modbus menu is set to 2 but you only add one demo item—update AddBadge to 1 or add the missing item.
  • If IModbusFactory should be available in all contexts, consider registering AddModbusFactory in ServiceCollectionSharedExtensions or centralizing service registration.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The badge count for the Modbus menu is set to 2 but you only add one demo item—update AddBadge to 1 or add the missing item.
- If IModbusFactory should be available in all contexts, consider registering AddModbusFactory in ServiceCollectionSharedExtensions or centralizing service registration.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc(Modbus): add IModbusFactory documentation

2 participants